package com.oxygen.pt.mapper;

import com.oxygen.pt.pojo.entity.AnomalyRecord;
import com.oxygen.pt.pojo.vo.AnomalyRecordVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface AnomalyRecordMapper {

    @Select("SELECT * FROM anomaly_record")
    List<AnomalyRecord> selectAll();

    /**
     * 异常记录筛选，依据时间
     * @param startDate
     * @param endDate
     * @return
     */
    @Select("SELECT COUNT(*) FROM anomaly_record " +
            "WHERE anomaly_time BETWEEN #{startDate} AND #{endDate}")
    Long getByDate(LocalDate startDate, LocalDate endDate);

    /**
     * 插入异常记录
     * @param anomalyRecord 异常记录实体
     */
    @Insert("INSERT INTO anomaly_record (patient_id, patient_name, anomaly_info, anomaly_status, anomaly_time, chamber_number) " +
            "VALUES (#{patientId}, #{patientName}, #{anomalyInfo}, #{anomalyStatus}, #{anomalyTime}, #{chamberNumber})")
    void insertAnomalyRecord(AnomalyRecord anomalyRecord);

    @Select("SELECT id, patient_id      AS patientId, "
            + "       patient_name    AS patientName, "
            + "       anomaly_info    AS anomalyInfo, "
            + "       anomaly_status  AS anomalyStatus, "
            + "       anomaly_time    AS anomalyTime, "
            + "       chamber_number  AS chamberNumber "
            + "FROM anomaly_record "
            + "ORDER BY anomaly_time DESC")
    List<AnomalyRecordVO> selectAnomalyList();
}
